import { Todo } from "@/types"
import { useState } from "react"
interface AddTodoProps {
    addTodo: (text: string) => void
}
function TodoAdd({addTodo}:AddTodoProps) {
    const [text, setText] = useState('')
    const handleSubmit = (e: React.FormEvent<HTMLFormElement>)=>{
        e.preventDefault()
        // 调用父组件传递过来的函数
        if(text.trim()===''){
            return
        }
        addTodo(text)
        setText('')
    }
    return (
       <div>
            <form onSubmit={handleSubmit}>
                <input type="text" value={text} onChange={(e)=>setText(e.target.value)} placeholder="请输入事项" />
                <button>新建事项</button>
            </form>
       </div>
    )
}

export default  TodoAdd 
        